package com.ys.service.amazonorder.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ys.config.MyConfig;
import com.ys.constant.AppConstant;
import com.ys.entity.sys.TbStaticConfig;
import com.ys.mapper.amazonorder.AmazonorderMapper;
import com.ys.mapper.sys.TbStaticConfigMapper;
import com.ys.service.amazonorder.TpAmazonShopOrderService;
import com.ys.util.HttpUtilYs;

@Service("tpAmazonShopOrderService")
public class TpAmazonShopOrderServiceImpl implements TpAmazonShopOrderService {
	@Autowired
	private AmazonorderMapper amazonorderMapper;
	@Autowired
	private TbStaticConfigMapper tbStaticConfigMapper;

	@Override
	public void updateLatestRefreshTime() {

		TbStaticConfig tbStaticConfig = new TbStaticConfig().setKeyOne(AppConstant.AMAZON_SHOP_ORDER_REFRESH).queryFirst();
		
		tbStaticConfigMapper.update(tbStaticConfig);
	}

	@Override
	public void notify1_5_TO_DO_COUNT() {
		Thread t = new Thread(() -> {
			
			String body = "";
			String urlNotify = MyConfig.getUrlDomain() + "/api/outer/amazonShop/addTpSaleDataSheet";
			HttpUtilYs.sendPostJSON(urlNotify, body);
		});
		t.start();
	}

	@Override
	public void notify1_5_TO_DO_ANALYSIS() {
		Thread t = new Thread(() -> {
			
			String body = "";
			String urlNotify = MyConfig.getUrlDomain() + "/api/outer/notify/addTpAnalysisDailyTargetByShop";
			HttpUtilYs.sendPostJSON(urlNotify, body);
		});
		t.start();
	}

	@Override
	public void updateBatch() {
		amazonorderMapper.updateTpAmazonShopOrderBatch();
	}

	@Override
	public void addBatchFromLatest(String sellerId) {
		amazonorderMapper.deleteBatchTpAmazonShopOrderBySeller(sellerId);
		amazonorderMapper.insertBatchTpAmazonShopOrderBySeller(sellerId);
		
	}
}
